home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
-
- modinit.c - standard initialisation for Opus 5 modules
-
- ****************************************************************************/
-
- #ifndef _DOPUS_MODULE_DEF
- #define _DOPUS_MODULE_DEF
- #include <dopus/modules.h>
- #endif
-
- #ifndef CLIB_EXEC_PROTOS_H
- #include <clib/exec_protos.h>
- #include <pragmas/exec_pragmas.h>
- #endif
-
- #ifndef EXEC_MEMORY_H
- #include <exec/memory.h>
- #endif
-
- #ifndef CLIB_LOCALE_PROTOS_H
- #include <clib/locale_protos.h>
- #include <pragmas/locale_pragmas.h>
- #endif
-
- /********************************************************************/
-
- // SAS/C stuff
- int __saveds __UserLibInit(void);
- void __saveds __UserLibCleanup(void);
-
- struct Library *DOSBase;
- struct Library *AslBase;
- struct Library *DOpusBase;
- struct Library *LocaleBase;
- struct Library *UtilityBase;
- struct Library *GadToolsBase;
- struct Library *IntuitionBase;
- struct Library *RexxSysBase;
-
- APTR mempool; // a globally mempool for the module
-
- // Locale pointer
- struct DOpusLocale *locale;
-
-
- // Library initialisation code
- __saveds __UserLibInit()
- {
- // Initialise pointers
- AslBase = 0;
- DOpusBase=0;
- LocaleBase=0;
- UtilityBase=0;
- GadToolsBase = 0;
- IntuitionBase = 0;
- RexxSysBase=0;
-
- locale=0;
- mempool = NULL;
-
- // Get DOS library (can't really fail)
- DOSBase=OpenLibrary("dos.library",0);
-
- // Open other libraries we need
- if( !(AslBase = OpenLibrary("asl.library", 37)) ||
- !(DOpusBase=OpenLibrary("dopus5.library",55)) ||
- !(UtilityBase=OpenLibrary("utility.library",37)) ||
- !(GadToolsBase = OpenLibrary( "gadtools.library", 37)) ||
- !(IntuitionBase = OpenLibrary( "intuition.library", 37)) ||
- !(RexxSysBase=OpenLibrary("rexxsyslib.library",0)) )
- return 1;
-
- if( !(mempool = NewMemHandle(4096, 3072, MEMF_CLEAR|MEMF_PUBLIC)) ||
- !(locale = AllocMemH(mempool, sizeof(struct DOpusLocale))) )
- {
- return 1;
- }
-
-
- init_locale_data(locale);
-
- // Open locale library
- if (LocaleBase=OpenLibrary("locale.library",38))
- {
- // Store library pointer
- locale->li_LocaleBase=LocaleBase;
-
- // Open catalog if name supplied
- if (module_info.locale_name)
- {
- struct TagItem tags[2];
-
- // If MODULEF_CATALOG_VERSION is set, we do version checking
- tags[0].ti_Tag=(module_info.flags&MODULEF_CATALOG_VERSION)?OC_Version:TAG_IGNORE;
- tags[0].ti_Data=module_info.ver;
- tags[1].ti_Tag=TAG_END;
-
- // Open catalog
- locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,tags);
- }
-
- // Get default lolale
- locale->li_Locale=OpenLocale(0);
- }
-
- return NULL; // Succeeded
- }
-
-
- // Clean up
- void __saveds __UserLibCleanup()
- {
-
- if( mempool )
- {
- if( locale )
- {
- if( LocaleBase )
- {
- CloseLocale(locale->li_Locale);
- CloseCatalog(locale->li_Catalog);
- CloseLibrary(LocaleBase);
- }
- FreeMemH(locale);
- }
-
- FreeMemHandle( mempool );
- }
-
- // Close libraries
- CloseLibrary( AslBase );
- CloseLibrary(DOpusBase);
- CloseLibrary(UtilityBase);
- CloseLibrary(RexxSysBase);
- CloseLibrary( GadToolsBase );
- CloseLibrary( IntuitionBase );
- CloseLibrary(DOSBase);
- }
-
-
- // This routine is called by Opus to find out what the module does
- ModuleInfo *__asm __saveds L_Module_Identify(register __d0 int num)
- {
- // Return module information
- if (num==-1) return &module_info;
-
- // Valid function number?
- if (num>module_info.function_count || !(module_info.function[num].desc)) return 0;
-
- // Return function description
- return (ModuleInfo *)DOpusGetString(locale,module_info.function[num].desc);
- }
-
- /********************************************************************/
-
-
-
-